package servlet;

import pojo.Music;
import utils.MybatsUtils;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import org.apache.ibatis.session.SqlSession;
import java.io.IOException;

@WebServlet(name="FindMusicByIdServlet",value = "/findMusicById")
public class FindMusicByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //1 获取参数
        String id=request.getParameter("id");
        //2 使用Mybatis将查询音乐信息
        SqlSession sqlSession= MybatsUtils.getSqlSession();
        Music m=sqlSession.selectOne("MusicMapper.findMusicById",id);
        request.setAttribute("music",m);
        sqlSession.close();
        RequestDispatcher rd=request.getRequestDispatcher("/updateMusic.jsp");
        rd.forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }
}
